<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <el-button
              v-if="isAuth('module:contract:category:form')"
              type="success"
              icon="Plus"
              @click="router.push({ name: 'module_contract_category_form' })">
              {{ i18n('common.create') }}
            </el-button>
          </div>
        </div>
        <div class="admin_main_block_right">
          <div>
            <el-button
              v-if="isAuth('module:contract:category:delete')"
              type="danger"
              icon="Delete"
              @click="deleteHandle()">
              {{ i18n('common.batch_delete') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_main_block_select">
        <div class="input">
          <el-input
            v-model="dataForm.keyword"
            :placeholder="i18n('common.please_input') + i18n('common.keyword')"
            clearable>
          </el-input>
        </div>
        <div class="date">
          <el-date-picker v-model="dataForm.create_time" type="daterange" :range-separator="$t('common.to')" :start-placeholder="$t('common.start_time')" :end-placeholder="$t('common.end_time')" clearable>
          </el-date-picker>
        </div>
        <div class="input">
          <el-button icon="Search" @click="getDataList(true)">
            {{ i18n('common.search') }}
          </el-button>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table
          :data="dataList"
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandle">
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" fixed="left" width="70">
          </el-table-column>

          <el-table-column prop="picture" :label="i18n('contract.category.picture')" width="120">
            <template v-slot="scope">
              <el-image class="cx-list-image" :src="scope.row.picture">
                <template v-slot:error>
                  <div class="image-slot">
                    <el-icon><Picture /></el-icon>
                  </div>
                </template>
              </el-image>
            </template>
          </el-table-column>

          <el-table-column prop="chinese_title" :label="i18n('contract.category.chinese_title')" min-width="120">
          </el-table-column>

          <el-table-column prop="english_title" :label="i18n('contract.category.english_title')" min-width="120">
          </el-table-column>

          <el-table-column prop="sort" :label="i18n('common.sort')" width="80">
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="290">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:contract:category:form')"
                type="primary"
                icon="Edit"
                @click="router.push({ name: 'module_contract_category_form', query: { id: scope.row.id } })">
                {{ i18n('common.update') }}
              </el-button>

              <el-button
                v-if="isAuth('module:contract:category:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                {{ i18n('common.delete') }}
              </el-button>

              <el-dropdown class="more">
                <el-button icon="More">
                  {{ i18n('common.more') }}
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item v-if="isAuth('module:contract:authority:list')" @click="router.push({ name: 'module_contract_authority_list', query: { category_id: scope.row.id } })">
                      {{ i18n('contract.authority.info') }}
                    </el-dropdown-item>
                    <el-dropdown-item v-if="isAuth('module:contract:list')" @click="router.push({ name: 'module_contract_list', query: { category_id: scope.row.id } })">
                      {{ i18n('contract.info') }}
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>

        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="contract-category-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('contract/category')

  const dataForm = reactive([
    'keyword',
    'create_time',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)

  onMounted(() => {
    getDataList(model)
  })
</script>
